﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace df
{
    public partial class option : share
    {
        public option()
        {
            InitializeComponent();

            auto_save_delay.Value = config.autoSaveDelay;

            string[] formLocation = config.formLocation.Split('|');
            location_x.Value = formLocation[0].ToInt32();
            location_y.Value = formLocation[1].ToInt32();
            string[] formSize = config.formSize.Split('|');
            sizeW.Value = formSize[0].ToInt32();
            sizeH.Value = formSize[1].ToInt32();
            txt_bg.Panel1.BackColor = System.Drawing.ColorTranslator.FromHtml(config.textBgcolor);

            font_show.Font = new FontConverter().ConvertFromString(config.textFont) as Font;

        }
        /// <summary>
        /// 提交
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void submit_Click(object sender, EventArgs e)
        {
            config.autoSaveDelay = auto_save_delay.Value.ToInt32();
            config.formLocation = string.Format("{0}|{1}", location_x.Value, location_y.Value);
            config.textBgcolor = System.Drawing.ColorTranslator.ToHtml(txt_bg.Panel1.BackColor);
            //config.textFont = string.Format("{0}|{1}", font_show.Font.FontFamily.Name, font_show.Font.Size);
            config.textFont = new FontConverter().ConvertToString(font_show.Font);
            config.formSize = string.Format("{0}|{1}", sizeW.Value, sizeH.Value);

            if (updateConfig(config.auto_save_delay, config.autoSaveDelay) > 0 && updateConfig(config.form_location, config.formLocation) > 0 && updateConfig(config.form_size, config.formSize) > 0 && updateConfig(config.text_bgcolor, config.textBgcolor) > 0 && updateConfig(config.text_font, config.textFont) > 0)
            {


                DialogResult = DialogResult.OK;

            }




        }

        private void cancel_Click(object sender, EventArgs e)
        {
            Dispose();
        }

        private void reg_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            reg r = new reg();

            if (r.ShowDialog() == DialogResult.OK)
            {
                err.Text = r.err.Text;
                r.Dispose();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            color.Color = txt_bg.Panel1.BackColor;
            if (color.ShowDialog() == DialogResult.OK)
            {
                txt_bg.Panel1.BackColor = color.Color;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            fontDialog1.Font = font_show.Font;
            if (fontDialog1.ShowDialog() == DialogResult.OK)
            {
                font_show.Font = fontDialog1.Font;
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            location_x.Value = config.formX;
            location_y.Value = config.formY;
        }

        private void button4_Click(object sender, EventArgs e)
        {
            sizeW.Value = config.formW;
            sizeH.Value = config.formH;
        }
    }
}
